<?php
namespace app\index\controller;
use think\Controller;
use think\captcha\Captcha;
class Contact extends  Controller
{
    public function contact()
    {
        return view();
    }

    public function feedback()
    {
        return view();
    }
    public function sendEmail(){
            $formData=input('post.');
            $code=input('code');
           $captcha = new Captcha();

           $result=$captcha->check($code);
            if($result===false){
           $this->error('验证码错误!');
           }

        $validate = \think\Validate::make([
            'username'  => 'require',
            'tel' => 'require',
            'email' => 'require',
            'title' => 'require',
            'advice' => 'require',
        ],[
            'username.require'=> '姓名不能为空',
            'tel.require'     => '联系电话不能为空',
            'email.require'   => '邮箱不能为空',
            'title.require'   => '标题不能为空',
            'advice.require'  => '意见不能为空',
        ]);

        unset($formData['code']);



        if (!$validate->check($formData)) {
            $this->error($validate->getError()); die;
        }
//         unset($formData['code']);
         $username=input('username');
         $tel=input('tel');
         $email=input('email');
         $title=input('title');
         $advice=input('advice');
         $sendEmail='huxinbin@hcclub.org';
         $content='给华创的建议:'.$advice.'<br/>建议人:'.$username.'<br/>电话:'.$tel.'<br/>邮箱:'.$email;
         $flag = sendMail($sendEmail, $title,$content);
         if($flag){
             $this->success('发送邮件成功!');
        }else{
             $this->error('发送邮件失败!');
         }

    }
    public function verify()
    {
        $captcha = new Captcha();
        $captcha->imageW=121;
        $captcha->imageH = 32;  //图片高
        $captcha->fontSize =14;  //字体大小
        $captcha->length   = 4;  //字符数
        $captcha->fontttf = '5.ttf';  //字体
        $captcha->expire = 30;  //有效期
        $captcha->useNoise = false;  //不添加杂点
        return $captcha->entry();

    }



}
